package com.cn.intelligence.resetful.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cn.intelligence.pojo.TaotaoResult;
import com.cn.intelligence.pojo.TbCart;
import com.cn.intelligence.pojo.TbOrder;
import com.cn.intelligence.pojo.Vip;
import com.cn.intelligence.resetful.pojo.Conts;
import com.cn.intelligence.resetful.service.ShoppingService;

/**
 * 购物车信息
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/Api/Shopping/")
public class ShoppingController {
	
	@Autowired
	public ShoppingService shoppingService;
	

    /**
     * 添加到购物车
     * @throws Exception 
     */
    @RequestMapping(value = "add",method = RequestMethod.POST)
    @ResponseBody
	public TaotaoResult addCart(TbCart tbCart ) throws Exception{
    	 TaotaoResult taotaoResult= shoppingService.saveCart(tbCart);
        return taotaoResult;
	}
    /**
     * 调试完成 2017-08-09
     * 获取个人的购物车信息
     * @throws Exception 
     */
    @RequestMapping(value = "cartlist",method = RequestMethod.POST)
    @ResponseBody
	public TaotaoResult getCartlist(Long userid){
		TaotaoResult taotaoresult = new TaotaoResult();
		taotaoresult.setMsg(Conts.SUCCESS_MSG);
		taotaoresult.setStatus(Conts.SUCCESS_CODE);
		taotaoresult.setData(shoppingService.getCartlist(userid));
		return taotaoresult;
	}
    
    /** 
     * 调试成功
     * 删除购物商品信息
     */
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    @ResponseBody
	public TaotaoResult deleteUserCart(Long cardId){
		TaotaoResult taotaoresult = shoppingService.deleteUserCart(cardId);
		return taotaoresult;
	}
    /**
     * 获取购物车中的商品信息
     * @throws Exception 
     */
    @RequestMapping(value = "buyCart",method = RequestMethod.POST)
    @ResponseBody
	public TaotaoResult getBuyCat(String cart_id, Long uid){
		TaotaoResult taotaoresult = new TaotaoResult();
		taotaoresult.setMsg(Conts.SUCCESS_MSG);
		taotaoresult.setStatus(Conts.SUCCESS_CODE);
		taotaoresult.setData(shoppingService.getBuyCat(cart_id,uid));
		return taotaoresult;
	}
    
    /**
     * 创建订单
     * @throws Exception 
     */
    @RequestMapping(value = "payment",method = RequestMethod.POST)
     @ResponseBody
 	public TaotaoResult payment(TbOrder tborder) throws Exception{
    	TbOrder createdOrder = shoppingService.addpayment(tborder);
    	return TaotaoResult.ok(createdOrder);
 	}
    /**
     * 修改购物车商品信息
     */
    @RequestMapping(value = "upCart",method = RequestMethod.POST)
     @ResponseBody
 	public TaotaoResult upCart(TbCart tbCart){
    	TbCart newCart = shoppingService.updateCart(tbCart);
    	return TaotaoResult.ok(newCart);
 	}
    /**
     * 为用户发放优惠券
     * @param uid 用户ID;
     * @param statusdate 有效天数
     * @param amount 减免金额
     * @param fullMoney 满减条件
     */
    @RequestMapping(value = "setVipInfo",method = RequestMethod.POST)
     @ResponseBody
 	public TaotaoResult setVipInfo(Vip vip){
    	return TaotaoResult.ok(shoppingService.setVipInfo(vip));
 	}
    /**
     * 新用户发放优惠券
     * @param uid 用户ID;
     * @param statusdate 有效天数
     * @param amount 减免金额
     * @param fullMoney 满减条件
     */
    @RequestMapping(value = "setNewVipInfo",method = RequestMethod.POST)
     @ResponseBody
 	public TaotaoResult setNewVipInfo(Vip vip){
    	return TaotaoResult.ok(shoppingService.setNewVipInfo(vip));
 	}
    /**
     * 为用户发放优惠券
     * @param uid 用户ID;
     */
    @RequestMapping(value = "getVipInfo",method = RequestMethod.POST)
     @ResponseBody
 	public TaotaoResult getVipInfo(Vip vip){
    	return TaotaoResult.ok(shoppingService.getVipInfo(vip));
 	}
    
}
